/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package datas;

import beans.Product;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author havn
 */
public class ProductObj {

    private connector con;
    //private List<Product> products;
    
    public ProductObj() {
        con = new connector();
        //products = listProduct();
    }

    public List<Product> listProduct() {
        List list = new ArrayList();
        try {
            CallableStatement call = con.getCon().prepareCall("{call ListProduct()}");
            ResultSet rs = call.executeQuery();
            while (rs.next()) {
                Product p = new Product();
                p.setId(rs.getInt("id"));
                p.setImage(rs.getString("ProductImage"));
                p.setName(rs.getString("ProductName"));
                p.setPrice(rs.getInt("Price"));
                list.add(p);
            }
            return list;
        } catch (SQLException ex) {
            ex.getStackTrace();
        }
        return null;
    }

//    /**
//     * @return the products
//     */
//    public List<Product> getProducts() {
//        return products;
//    }
}
